package com.sl.hx.shop.view.dialog;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.sl.hx.shop.R;
import com.sl.hx.shop.ui.home.activity.SearchActivity;
import com.sl.hx.shop.utils.ToastUtil;

public class homeSearchPop extends PopupWindow implements View.OnClickListener{

    private float density = 1.0f;
    private Context mContext;
    private RelativeLayout searchlayout;
    public homeSearchPop(Context context) {
        mContext=context;
        View view = View.inflate(context, R.layout.pop_home_search, null);
        searchlayout=view.findViewById(R.id.pop_search);
        setContentView(view);
        initPopupWindow();
        //设置popwindow的宽高，这个数字是多少就设置多少dp，注意单位是dp
        setHeight((int)(48*density+0.5f));
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    }

    //初始化popwindow
    private void initPopupWindow() {
        setAnimationStyle(R.style.popwindowAnim);//设置动画
//        setFocusable(true);
//        setTouchable(true);
        searchlayout.setOnClickListener(this);
        setOutsideTouchable(false);
        setBackgroundDrawable(new BitmapDrawable());
        density = mContext.getResources().getDisplayMetrics().density;//
    }



    @Override
    public void onClick(View v) {
       switch (v.getId()){
           case R.id.pop_search:
               Intent intent = new Intent(mContext, SearchActivity.class);
               mContext.startActivity(intent);
               break;
       }
    }
}
